/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RecipeView.java
 *
 * Created on 2011-jan-28, 11:52:55
 */

package recipesearch;
import se.chalmers.ait.dat215.lab2.*;
import java.util.*;
/**
 *
 * @author max
 */
public class RecipeView extends javax.swing.JPanel {
    private Recipe recipe;

    /** Creates new form RecipeView */
    public RecipeView() {
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        upperPanel = new javax.swing.JPanel();
        titleLbl = new javax.swing.JLabel();
        ingredientLbl = new javax.swing.JLabel();
        imageLbl = new javax.swing.JLabel();
        infoLbl = new javax.swing.JLabel();
        descriptionLbl = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(recipesearch.RecipeSearchApp.class).getContext().getResourceMap(RecipeView.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N

        upperPanel.setBackground(resourceMap.getColor("upperPanel.background")); // NOI18N
        upperPanel.setName("upperPanel"); // NOI18N

        titleLbl.setText(resourceMap.getString("titleLbl.text")); // NOI18N
        titleLbl.setName("titleLbl"); // NOI18N

        ingredientLbl.setText(resourceMap.getString("ingredientLbl.text")); // NOI18N
        ingredientLbl.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        ingredientLbl.setName("ingredientLbl"); // NOI18N
        ingredientLbl.setPreferredSize(null);

        imageLbl.setIcon(resourceMap.getIcon("imageLbl.icon")); // NOI18N
        imageLbl.setText(resourceMap.getString("imageLbl.text")); // NOI18N
        imageLbl.setName("imageLbl"); // NOI18N

        infoLbl.setText(resourceMap.getString("infoLbl.text")); // NOI18N
        infoLbl.setName("infoLbl"); // NOI18N

        org.jdesktop.layout.GroupLayout upperPanelLayout = new org.jdesktop.layout.GroupLayout(upperPanel);
        upperPanel.setLayout(upperPanelLayout);
        upperPanelLayout.setHorizontalGroup(
            upperPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(upperPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(upperPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(titleLbl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 267, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ingredientLbl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 252, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 50, Short.MAX_VALUE)
                .add(upperPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(upperPanelLayout.createSequentialGroup()
                        .add(infoLbl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(37, 37, 37))
                    .add(upperPanelLayout.createSequentialGroup()
                        .add(imageLbl)
                        .addContainerGap())))
        );
        upperPanelLayout.setVerticalGroup(
            upperPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(upperPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(upperPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(titleLbl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(infoLbl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(upperPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(upperPanelLayout.createSequentialGroup()
                        .add(imageLbl)
                        .addContainerGap(40, Short.MAX_VALUE))
                    .add(ingredientLbl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)))
        );

        descriptionLbl.setText(resourceMap.getString("descriptionLbl.text")); // NOI18N
        descriptionLbl.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        descriptionLbl.setMaximumSize(getPreferredSize());
        descriptionLbl.setName("descriptionLbl"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(upperPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(descriptionLbl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 447, Short.MAX_VALUE)
                .add(20, 20, 20))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(upperPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(descriptionLbl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel descriptionLbl;
    private javax.swing.JLabel imageLbl;
    private javax.swing.JLabel infoLbl;
    private javax.swing.JLabel ingredientLbl;
    private javax.swing.JLabel titleLbl;
    private javax.swing.JPanel upperPanel;
    // End of variables declaration//GEN-END:variables

    public void setIngredients() {
        List<Ingredient> ingList = this.recipe.getIngredients();
        String ingString = "<html><h2>Ingredienser</h2>";
        for(Ingredient i: ingList){
            ingString+= i.getAmount() + " " + i.getUnit() + " <b>" + i.getName() + "</b><br>";
        }
        ingredientLbl.setText(ingString);
    }

    public void setRecipe(Recipe recipe) {
        this.recipe = recipe;
        this.setIngredients();
        imageLbl.setIcon(recipe.getImage());
        titleLbl.setText("<html><h1>" + recipe.getName() + "</h1>");
        infoLbl.setText("<html><b>Tid: </b>"+recipe.getTime()+" min, <b>Kök: </b>"+recipe.getCuisine()
                + "<br><b>Pris: </b>"+recipe.getPrice()+ " SEK, <b>Svårighetsgrad: </b>"+recipe.getDifficulty());
        descriptionLbl.setText("<html><h2>Beskrivning</h2>"+recipe.getDescription());

    }

}
